package com.yanqu.road.server.cmd.activity.crosspasture.cross;

import com.yanqu.road.entity.activity.pasture.PastureConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PastureProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.crosspasture.CrossPastureModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.crosspasture.CrossPastureMgr;
import com.yanqu.road.server.manger.activity.pasture.PastureMgr;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CHANNEL_CROSS_PASTURE_GAME_OVER, desc = "")
public class PastureGameOverDataCmd extends AbstractCommand {

    private int activityId;
    private int rank;
    private boolean isPractice;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        PastureProto.CrossPastureGetRankRespMsg reqMsg = PastureProto.CrossPastureGetRankRespMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        rank = reqMsg.getRank();
        isPractice = reqMsg.getIsPractice();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        PastureConfig config = CrossPastureMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            return;
        }
        if (activityId != config.getActivityInfo().getActivityId()) {
            return;
        }
        player.getModule(CrossPastureModule.class).gameOverHandler(isPractice, rank);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
